import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { OtcCustomerService } from '@core/routes-services/otc-customer.service';
import { OTC_ROLE_OPTION } from '../../../../constant/dictionary';
import { ActivatedRoute, Params, Router } from '@angular/router';

@Component({
  selector: 'app-otc-cus-view',
  templateUrl: './otc-cus-view.component.html',
  styles: [`
    h2 {
      border-bottom: 1px solid #1890ff;
      color: #1890ff;
      padding-top: 10px;
    }
  `],
})
export class OtcCusViewComponent implements OnInit {

  id: any = 0;// 默认 0
  entity: any = {};
  isLoading: boolean = true;
  index:any = 0


  cusAddress:any[] = [];
  userRoleOption: any [] = OTC_ROLE_OPTION;
  constructor( private router: Router,
               private route: ActivatedRoute,
              private otcCustomerService: OtcCustomerService,
              public message: NzMessageService,
  ) {
  }

  ngOnInit(): void {
    this.route.queryParams.forEach((params: Params) => {
      let id =  +params['id'];
      if(!isNaN(id)){
        this.id = +params['id'];
        this.initEntity();
        this.initCusAddress();
      }
    });
  }
  initEntity(){
    this.isLoading = true;
    this.otcCustomerService.detail(this.id).then((res) => {
      if (res.status.toString().startsWith('20')) {
        this.entity = res.data;
      } else {
        this.message.warning(res.message);
      }
      this.isLoading = false;
    }, error => {
      this.message.error(error.message ? error.message : error.error);
      this.isLoading = false;
    });
  }
  initCusAddress(){
    this.otcCustomerService.cusAddress(this.id).then((res) => {
      console.log(res )
      if (res.status.toString().startsWith("20")) {
        this.cusAddress = res.data?res.data:[];
      } else {
        this.message.warning(res.message);
      }
    }, error => {
      this.message.error(error.message ? error.message : error.error)
    });
  }

}
